#!/bin/sh

# Copyright 2022 Felix Freeman <libsys@hacktivista.org>
#
# This script is licensed under the 'MIT No Attribution' license terms. I don't
# want attribution nor exclusive rights over it, but I'd love that you free your
# software too.

# Environment variables
#
# - CONTAINER: HAWESE lxd container name

CONTAINER=${CONTAINER:-hawese}
lxc launch images:debian/11 "$CONTAINER"
printf "uid %s 1000\ngid %s 33" "$(id -u)" "$(id -g)" |
	lxc config set "$CONTAINER" raw.idmap -
lxc config device add "$CONTAINER" src disk source="$(pwd)" path="/opt/hawese"
lxc restart "$CONTAINER"
sleep 2
lxc exec "$CONTAINER" -- \
	env HAWESE_ENV="$HAWESE_ENV" \
	env ENDPOINT="$ENDPOINT" \
	env CORS_ENDPOINT="$CORS_ENDPOINT" \
	env PROJECTS="$PROJECTS" \
	env WALLET_ADD_FUNDS_URL="$WALLET_ADD_FUNDS_URL" \
	env PAYMENT_RETURN_URL="$PAYMENT_RETURN_URL" \
	env CERTBOT_EMAIL="$CERTBOT_EMAIL" \
	env XDEBUG_CLIENT_HOST="${XDEBUG_CLIENT_HOST:-_gateway.lxd}" \
	sh -c /opt/hawese/setup/setup.sh
